<?php
require_once 'lib/controller.php';
?>
<html>
<head>
</head>
<body>
<?php
if (empty($_GET['personid'])) {
?>
<form method="GET" action="<?php $_SERVER['PHP_SELF']; ?>">
    <p><label>Person Id:</label> <input type="text" name="personid" value=""></p>
</form>
<?
} else {
    $personId = intval($_GET['personid']);
    $sql = 'SELECT * FROM Person WHERE ID = ' . $personId;
    $result = $db->query($sql);
    $row = $db->fetch($result);
    $lastName = $row['Surname'];
    $firstName = $row['FirstNames'];
    $alsoKnownAs = $row['AlsoKnownAs'];
    $neeName = $row['NeeName'];
    $formerName = $row['FormerName'];
    $deathDate = $row['DeathDate'];
    $birthDate = $row['BirthDate'];
    $age = $row['Age'];
    $ageMeasure = $row['AgeMeasure'];
    $cityTownId = $row['CityTownID'];
    $formerCityTownId = $row['FormerCityTownID'];
    $regionId = $row['RegionID'];
    $countryId = $row['CharityID'];
    $charityId = $row['CharityID'];
    $funeralHomeId = $row['FuneralHomeID'];
    $otherInfo = $row['OtherInfo'];
?>
<form method="POST" action="modifyperson2.php">
    <p>This form allows you to test the modify person code that is used by the insert application.</p>
    <p><label for="personid">Person Id: </label><input type="text" id="personid" name="ID" value="<?php echo $personId; ?>"></p>
    <p><label for="surname">Surname: </label><input type="text" id="surname" name="surname" value="<?php echo $lastName; ?>"></p>
    <p><label for="firstname">First Names: </label><input type="text" id="firstname" name="firstname" value="<?php echo $firstName; ?>"></p>
    <p><label for="alsoknownas">Also Known As: </label><input type="text" id="alsoknownas" name="alsoknownas" value="<?php echo $alsoKnownAs; ?>"></p>
    <p><label for="neename">Nee Name: </label><input type="text" id="neename" name="neename" value="<?php echo $neeName; ?>"></p>
    <p><label for="formername">Former Name: </label><input type="text" id="formername" name="formername" value="<?php echo $formerName; ?>"></p>
    <p><label for="deathdate">Death Date: </label><input type="text" id="deathdate" name="deathdate" value="<?php echo $deathDate; ?>"></p>
    <p><label for="birthdate">Birth Date: </label><input type="text" id="birthdate" name="birthdate" value="<?php echo $birthDate; ?>"></p>
    <p>Note: Dates from the Insert app are in this format: YYYY-MM-DD HH:MM:SS
    <p><label for="age">Age: </label><input type="text" id="age" name="age" value="<?php echo $age; ?>"></p>
    <p><label for="agemeasure">Age Measure: </label><input type="text" id="agemeasure" name="agemeasure" value="<?php echo $ageMeasure; ?>"></p>
    <p>
        City/Town:
        <select name="citytown">
            <option value="<?php echo $cityTownId; ?>">Default</option>
            <option value="191">Auckland</option>
            <option value="5562">Wellington</option>
            <option value="600">Christchurch</option>
            <option value="803">Dunedin</option>
        </select>
    </p>
    <p>
        Former City/Town:
        <select name="formercitytown">
            <option value="<?php echo $formerCityTownId; ?>">Default</option>
            <option value="191">Auckland</option>
            <option value="5562">Wellington</option>
            <option value="600">Christchurch</option>
            <option value="803">Dunedin</option>
        </select>
    </p>    
    <p>
        Region:
        <select name="region">
            <option value="<?php echo $regionId; ?>">Default</option>
        </select>
    </p>
    <p>
        Country:
        <select name="country">
            <option value="<?php echo $countryId; ?>">New Zealand</option>
        </select>
    </p>
    <p><label for="charity">Charity: </label><input type="text" id="charity" name="charity" value="<?php echo $charityId; ?>"></p>
    <p>
        Funeral Home:
        <select name="funeralhome">
            <option value="<?php echo $funeralHomeId; ?>">Default</option>
            <option value="212">sues funeral home</option>
            <option value="218">melissa</option>
        </select>
    </p>
    <p><label for="othernotes">Other Info: </label><input type="text" id="othernotes" name="othernotes" value="<?php echo $otherInfo; ?>"></p>
    <p><input type="submit" value="Modify Person"></p>
</form>
<p>After you have added the person, you should see a number shown on the page. That number is the personid number.</p>
<p>Add that number here and open the beta remembrance page to check that the persons details properly display.</p>
<form method="GET" action="http://beta.amemorytree.co.nz/remembrance.php">
    <p>
        <label for="personid">remembrance.php?personid=<?php echo $personId; ?></label>
        <input type="text" id="personid" name="personid">
        <input type="submit" value="Open remembrance page">
    </p>
</form>
<p>If a funeral home was entered for the person, a setting in their funeral home details called AddListingNotify specifies whether they receive an email or not. Currently all funeral homes have this set to true.</p>
<?php
}
?>
</body>
</html>
